package cn.chenhuanming.chuanzhi.controller;

import cn.chenhuanming.chuanzhi.service.ShareService;
import cn.chenhuanming.chuanzhi.service.StaffService;
import cn.chenhuanming.chuanzhi.service.VoteService;
import cn.chenhuanming.chuanzhi.util.entity.Share;
import cn.chenhuanming.chuanzhi.util.entity.Staff;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * Created by Administrator on 2017-05-08.
 */
@RestController
public class MeController {
    @Autowired
    ShareService shareService;

    @Autowired
    StaffService staffService;

    @Autowired
    VoteService voteService;

    @PreAuthorize("authenticated")
    @PostMapping("/me")
    void updateMe(Staff staff){
        staffService.updateMe(staff);
    }

    @PreAuthorize("authenticated")
    @PostMapping("/newShare")
    void newShare(Share share){
        shareService.newShare(share);
    }

    @PreAuthorize("authenticated")
    @PostMapping("/changePassword")
    boolean changePassword(String oldPassword,String newPassword){
        return staffService.changePassword(oldPassword,newPassword);
    }

    @PreAuthorize("authenticated")
    @PostMapping("/vote")
    void vote(Integer optionId){
        voteService.vote(optionId);
    }

    @PreAuthorize("authenticated")
    @PostMapping("/finishVote")
    void finishVote(String voteId){
        voteService.finishVote(voteId);
    }

    @PreAuthorize("authenticated")
    @PostMapping("/deleteShare")
    void deleteShare(String shareId){
        shareService.delete(shareId);
    }

}
